package Test;

import java.io.File;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import Task25.Controller;

public class makeDirFileTest {
	
	private String type;
	
	@Test
	public void makeAbsDir(){
		String path = "C:\\Test\\Test4";
		String[] command = {"mkdir",path};
		Controller.gui(command);
		type = "dir";
		assertTest(path);
		refresh(path);
	}
	
	@Test
	public void makeAbsFile(){
		String path = "C:\\Test\\Test1\\4.txt";
		String[] command = {"mkfile",path};
		Controller.gui(command);
		type = "file";
		assertTest(path);
		refresh(path);
	}
	
	@Test
	public void makeRelDir(){
		// change the work directory on the Test
		Controller.gui(new String[] { "cd", "C:\\Test" });
		String path = "Test4";
		String[] command = {"mkdir",path};
		Controller.gui(command);
		type = "dir";
		assertTest("C:\\Test\\"+path);
		refresh("C:\\Test\\"+path);
	}
	
	@Test
	public void makeRelFile(){
		// change the work directory on the Test
		Controller.gui(new String[] { "cd", "C:\\Test" });
		String path = "Test1\\4.txt";
		String[] command = {"mkfile",path};
		Controller.gui(command);
		type = "file";
		assertTest("C:\\Test\\"+path);
		refresh("C:\\Test\\"+path);
	}
	
	private void assertTest(String path) {
		File mkfile = new File(path);
		boolean flag = false;
		flag = mkfile.exists();
		if (type.equals("dir")) flag = mkfile.isDirectory();
		else flag = mkfile.isFile();
		assertTrue(flag);
	}
	
	private void refresh(String path) {
		String[] command = {"del", path};
		Controller.gui(command);
	}
}
